package com.example.myapplication.tack_04;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.myapplication.R;
import com.example.myapplication.tack_04.adapter.StopAdatert;
import com.example.myapplication.tack_04.data.StopData;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;

public class Stop extends AppCompatActivity {
    private ImageView exit;
    private RecyclerView list;
    private LinearLayout more;
    private List<StopData.RowsDTO> stopList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tack_04_stop);
        init();
        exit_();
        String url = "prod-api/api/park/lot/list?pageNum=1&pageSize=5";
        getStop(url);
        //点击查看更多
        more_();
        //详情
        getPage();
    }
    private void getPage() {
        
    }
    private void more_() {
        more.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        String url = "prod-api/api/park/lot/list?";
                        more.setVisibility(View.GONE);
                        getStop(url);

                    }
                });
            }
        });
    }

    private void getStop(String url) {

        OkHttpTool.doNetRequest(url, OkHttpTool.GET, StopData.class, new OkHttpTool.NetCallback() {
            @Override
            public void onSuccess(Object obj) {
                StopData stopData = (StopData) obj;
                stopList = stopData.getRows();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        stopAdapter();
                    }
                });
            }

            @Override
            public void onFailure(String msg) {

            }
        });
    }

    private void stopAdapter() {
        StopAdatert stopAdatert = new StopAdatert(stopList, Stop.this);
        LinearLayoutManager linearLayout = new LinearLayoutManager(Stop.this);
        list.setLayoutManager(linearLayout);
        list.setAdapter(stopAdatert);

    }

    private void exit_() {
        exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Stop.this.finish();
            }
        });
    }

    private void init() {
        exit = findViewById(R.id.exit);
        list = findViewById(R.id.list);
        more = findViewById(R.id.more);
    }
}